﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Security.Cryptography.X509Certificates;

namespace StsMngrConfigurationNS
{
	#region StsMngrConfiguration
	public class StsMngrConfiguration : ConfigurationSection
    {
		const string SectionName = "stsMngrConfiguration";
		static StsMngrConfiguration _configuration = null;

		public static StsMngrConfiguration Current
        {
            get
            {
                if (_configuration == null)
                {
					_configuration = (StsMngrConfiguration)ConfigurationManager.GetSection(SectionName);
                    if (_configuration == null)
                        throw new ConfigurationErrorsException("Configuration STS Section not found!");
                }
                return _configuration;
            }
        }

		[ConfigurationProperty("infoCard")]
		public InfoCardConfiguration InfoCard
		{
			get { return (InfoCardConfiguration)this["infoCard"]; }
		}
		[ConfigurationProperty("openIdInfoCard")]
		public InfoCardConfiguration OpenIdInfoCard
		{
			get { return (InfoCardConfiguration)this["openIdInfoCard"]; }
		}
	}
	#endregion

	#region InfoCardConfiguration
	public class InfoCardConfiguration : ConfigurationElement
	{
		public InfoCardConfiguration() { }

		[ConfigurationProperty("type", IsRequired = true)]
		public string Type
		{
			get { return (string)this["type"]; }
		}
		[ConfigurationProperty("details")]
		public CfgCollection Details
		{
			get { return (CfgCollection)this["details"]; }
		}
		[ConfigurationProperty("issuer")]
		public CfgCollection Issuer
		{
			get { return (CfgCollection)this["issuer"]; }
		}
		[ConfigurationProperty("claims")]
		public CfgCollection Claims
		{
			get { return (CfgCollection)this["claims"]; }
		}
		[ConfigurationProperty("tokenTypes")]
		public CfgCollection TokenTypes
		{
			get { return (CfgCollection)this["tokenTypes"]; }
		}
		[ConfigurationProperty("credentials")]
		public CfgCollection Credentials
		{
			get { return (CfgCollection)this["credentials"]; }
		}
	}
	#endregion

	#region CfgCollection
	[ConfigurationCollection(typeof(CfgElement))]
	public class CfgCollection : ConfigurationElementCollection
	{
		protected override ConfigurationElement CreateNewElement()
		{
			return new CfgElement();
		}
		protected override Object GetElementKey(ConfigurationElement element)
		{
			return ((CfgElement)element).Key;
		}
		public CfgElement GetElementByKey(string key)
		{
			foreach (CfgElement ce in this)
				if (ce.Key == key)
					return ce;
			return null;
		}
	}
	#endregion

	#region CfgElement
	public class CfgElement : ConfigurationElement
	{
		public CfgElement() { }

		[ConfigurationProperty("key", IsRequired = true, IsKey = true)]
		public string Key
		{
			get { return (string)this["key"]; }
		}
		[ConfigurationProperty("data", IsRequired = true)]
		public string Data
		{
			get { return (string)this["data"]; }
		}
		[ConfigurationProperty("edata")]
		public string Edata
		{
			get { return (string)this["edata"]; }
		}
		[ConfigurationProperty("storeLocation")]
		public StoreLocation StoreLocation
		{
			get { return (StoreLocation)this["storeLocation"]; }
		}
		[ConfigurationProperty("storeName")]
		public StoreName StoreName
		{
			get { return (StoreName)this["storeName"]; }
		}
	}
	#endregion
}
